package com.heima.controller;

import cn.hutool.db.PageResult;
import com.heima.pojo.SkuClass;
import com.heima.pojo.dto.SkuClassDto;
import com.heima.pojo.vo.PageResponse;
import com.heima.service.SkuClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/skuClass")
@RequiredArgsConstructor
@Api(tags = "商品类型管理")
public class SkuClassController {

    private final SkuClassService skuClassService;

    @PostMapping
    @ApiOperation("新增商品类型")
    private Boolean insertSkuClass(@RequestBody SkuClassDto skuClassDto) {
        Boolean result = skuClassService.insertSkuClass(skuClassDto);
        return result;
    }

    @GetMapping("/search")
    @ApiOperation("商品类型搜索")
    private PageResponse<SkuClass> selectPage(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                              @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                              @RequestParam(value = "name", required = false) String className) {
        return skuClassService.selectPage(pageIndex, pageSize, className);
    }

    @GetMapping("/{classId}")
    @ApiOperation("根据id查询商品类型")
    private SkuClass selectById(@PathVariable String classId) {
        return skuClassService.selectById(classId);
    }

    @PutMapping("/{classId}")
    @ApiOperation("根据id修改商品类型信息")
    private Boolean updateSkuClass(@PathVariable String classId,
                                   @RequestBody SkuClassDto dto) {
        return skuClassService.updateSkuClass(classId, dto);
    }

    @DeleteMapping("/{classId}")
    @ApiOperation("根据id删除商品类型")
    private Boolean deleteSkuClass(@PathVariable String classId) {
        return skuClassService.deleteSkuClass(classId);
    }

}
